package com.sanq.product.cab.lock.zookeeper;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.RetryNTimes;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * com.sanq.product.cab.locks.zookeeper.CuratorConfiguration
 *
 * @author sanq.Yan
 * @date 2020/3/1
 */
@Configuration
public class CuratorConfiguration {

    @Value("${curator.retryCount}")
    private int retryCount;             // 5

    @Value("${curator.elapsedTimeMs}")
    private int elapsedTimeMs;          // 5000

    @Value("${curator.connect}")
    private String connect;

    @Value("${curator.sessionTimeoutMs}")
    private int sessionTimeoutMs;       // 60000

    @Value("${curator.connectionTimeoutMs}")
    private int connectionTimeoutMs;    // 5000

    @Bean(initMethod = "start")
    public CuratorFramework curatorFramework() {
        return CuratorFrameworkFactory.newClient(
                connect,
                sessionTimeoutMs,
                connectionTimeoutMs,
                new RetryNTimes(retryCount, elapsedTimeMs)
        );
    }

}
